package Test1;

import java.util.Random;

/**
 *
 * @author 29284
 * @since 2024/11/29 20:41
 */
public class Role {
    private String roleName;
    private int blood;

    public Role() {
    }

    public Role(String roleName, int blood) {
        this.roleName = roleName;
        this.blood = blood;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }
    //攻击
    public void attack(Role role) {
        Random random = new Random();
        int hurt = random.nextInt(20)+1;
        int remainBlood = role.getBlood() - hurt;
        if (remainBlood < 0) {
            remainBlood = 0;
        }
        role.setBlood(remainBlood);
        System.out.println(this.getRoleName() + " 攻击了 " + role.getRoleName()+
              " 造成了 "+ hurt+"点伤害"+role.getRoleName()+"还剩" + remainBlood+"点血");

    }
}
